package cn.iocoder.yudao.module.engine.model.context;

import cn.iocoder.yudao.module.engine.dal.redis.engine.EngineCacheRedisDAO;
import cn.iocoder.yudao.module.resource.api.model.AudioDTO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

/**
 * 注意：所有存储的数据只能在同步流程中使用，否则如果用户发送多条消息会反序列化出来多个ctx会导致写入的数据丢失
 */
@Data
public class EngineSynStatusCacheContext {
    @JsonIgnore
    private String gameMatchId;
    @JsonIgnore
    private EngineCacheRedisDAO engineCacheRedisDAO;

    // 传感器状态
    private SensorStatusContext sensorStatusContext = new SensorStatusContext();

    // 回复类型的主音频
    private AudioDTO replyMainAudio;

    // 购买引导触发次数
    private int buyGuideTriggerCount = 0;

    public EngineSynStatusCacheContext() {
    }

    public EngineSynStatusCacheContext(String gameMatchId, EngineCacheRedisDAO engineCacheRedisDAO) {
        this.gameMatchId = gameMatchId;
        this.engineCacheRedisDAO = engineCacheRedisDAO;
    }

    // 同步到redis
    public void syn() {
        engineCacheRedisDAO.addEngineSynStatusCache(gameMatchId, this);
    }

    public synchronized void addBuyGuideTriggerCount() {
        buyGuideTriggerCount++;
    }
}
